package com.bxmdm.ragdemo;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import com.bxmdm.ragdemo.service.DeepseekService;
import com.bxmdm.ragdemo.service.EnglishQAService;
import com.bxmdm.ragdemo.dto.RagSearchResult;

/**
 * @Description: DeepSeek API 测试
 * @Author: assistant
 * @Date: 2025/6/10
 * @Version: 1.0
 */
@SpringBootTest
class DeepseekTest {

    @Autowired
    private DeepseekService deepseekService;
    
    @Autowired
    private EnglishQAService englishQAService;

    @Test
    void deepseekChatTest() {
        String message = "给我讲一个Java程序员的笑话吧";
        String response = deepseekService.callDeepseekSync(message);
        System.out.println("DeepSeek 响应: " + response);
    }

    @Test
    void deepseekEnglishTest() {
        String message = "What is the difference between 'affect' and 'effect'?";
        String response = deepseekService.callDeepseekSync(message);
        System.out.println("DeepSeek 英语回答: " + response);
    }
    
    @Test
    void ragAnswerFormatTest() {
        String question = "What is a verb?";
        int topK = 3;
        RagSearchResult result = englishQAService.ragAnswer(question, topK);
        
        System.out.println("=== 格式化RAG检索结果测试 ===");
        System.out.println("数量: " + result.getCount());
        System.out.println("结果:");
        
        if (result.getResults() != null) {
            for (int i = 0; i < result.getResults().size(); i++) {
                RagSearchResult.RagSearchItem item = result.getResults().get(i);
                System.out.println("  [" + (i + 1) + "] 相似度: " + String.format("%.3f", item.getSimilarity()));
                System.out.println("      问题: " + item.getQuestion());
                System.out.println("      答案: " + item.getAnswer());
                if (item.getOtherAnswers() != null && !item.getOtherAnswers().isEmpty()) {
                    System.out.println("      其他答案: " + item.getOtherAnswers());
                }
                System.out.println();
            }
        }
    }
}
